﻿using AutoMapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using NetTaste;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text.RegularExpressions;
using VM.BLL.Menu;
using VM.Common.DataUntil;
using VM.Common.EntityEnum;
using VM.Common.Result;
using VM.DAL.System.Code;
using VM.Entity.EntityDto.ShopCar;
using VM.Entity.EntityMap.DataBase;
using VM.Entity.EntityMap.Goods;
using VM.Entity.EntityMap.ICon;
using VM.Entity.EntityMap.Lunbo;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Menu;
using VM.Entity.EntityMap.MsgCode;
using VM.Entity.EntityMap.Region;
using VM.Entity.EntityMap.ShopCar;
using VM.Entity.EntityMap.System.Code;
using VM.Entity.EntityMap.Token;
using VM.Entity.EntityMap.Topic;
using VM.IBLL.IShopCar;
using VM.IBLL.Member;
using VM.IBLL.Menu;
using VM.IBLL.Token;
using VM.IBLL.Topic;
using VM.IDAL;
using VM.IDAL.ShopCar;


using static Dm.net.buffer.ByteArrayBuffer;

namespace VM.BLL.ShopCar
{
    public class ShopCarBLL : BaseBLL, IShopCarBLL
    {

        private readonly ISqlSuggarDAL _ISqlSuggarDAL;
        private readonly IShopCarDAL _IShopCarDAL;
        private readonly IMapper _IMapper;
        public ShopCarBLL(ISqlSugarClient client, ISqlSuggarDAL sqlSuggarDAL, IMenuBLL iMenuBLL, IShopCarDAL iShopCarDAL, IMapper iMapper)
        {
            _ISqlSuggarDAL = sqlSuggarDAL;
            _IShopCarDAL = iShopCarDAL;
            _IMapper = iMapper;


        }
         
        public ApiResult addShopCar(addshopCarDto obj)

        {
           
                sys_shopCar objRes = _IMapper.Map<addshopCarDto, sys_shopCar>(obj);
                ApiResult res = new ApiResult();
                bool Res = _IShopCarDAL.addShopCar(objRes,obj.addTypeId);
                if (Res)
                {
                    res.code = 200;
                    res.msg = $@"成功插入数据";
                }
                else
                {
                    res.code = 403;
                    res.msg = $@"成功失败";
                }
                return res;
            
        }

    


        /// <summary>
        /// 获取我的购物车列表数据，分页数据
        /// </summary>
        /// <param name="goodsTypeId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ApiDataResult<PagingData<getShopCarListDto>> getShopCarList(int userId, int pageIndex, int pageSize)
        {
            PagingData<getShopCarListDto> List = _IShopCarDAL.getShopCarList(userId, pageIndex, pageSize);
            ApiDataResult<PagingData<getShopCarListDto>> res = new ApiDataResult<PagingData<getShopCarListDto>>()
            {

                code = 200,
                msg = "获取成功",
                data = List
            };
            return res;
        }

        /// <summary>
        /// 根据购物车内码删除购物车记录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="shopCarId"></param>
        /// <returns></returns>
        public ApiResult deleteShopCarById(int userId, int shopCarId)
        {
            bool Res = _IShopCarDAL.deleteShopCarById(userId, shopCarId);
            if (Res) {
                ApiResult res = new ApiResult()
                {
                    code=200,
                    msg="删除成功"

                };
                return res;

            }
            else
            {

                ApiResult res = new ApiResult()
                {
                    code = 403,
                    msg = "删除失败"

                };
                return res;
            }
        }
    }
}




